#include <iostream>

using std::cout;
using std::endl;
//经典例子：交换两个变量的值

//参数的传递方式： 值传递
void swap(int x, int y) 
{
    int temp = x;
    x = y;
    y = temp;
}

//参数的传递方式： 地址传递
void swap2(int * px, int * py)
{
    int temp = *px;
    *px = *py;
    *py = temp;
}

//引用作为函数的参数
void swap3(int & x, int & y)
{
    //当使用引用时，x就代表传递过来的a, 
    //y就代表传递过来的b
    int temp = x;
    x = y;
    y = temp;
}

int main()
{
    int a = 3, b = 4;
    cout << "交换之前：" << endl;
    cout << "a:" << a << ", b: " << b << endl;
    //swap(a, b);
    //swap2(&a, &b);
    swap3(a, b);
    cout << "交换之后：" << endl;
    cout << "a:" << a << ", b: " << b << endl;

    return 0;
}

